package com.duan.laugh.sms.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.duan.laugh.common.core.util.Query;
import com.duan.laugh.common.core.util.R;
import com.duan.laugh.sms.api.entity.SmsAccessConfig;
import com.duan.laugh.sms.service.ISmsAccessConfigService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * <p>
 * controller
 * </p>
 *
 * @author liutf
 * @since 2019-11-07
 */
@Api(tags = "")
@RestController
@RequestMapping("/sms-access-config")
public class SmsAccessConfigController {
    @Autowired
    private ISmsAccessConfigService smsAccessConfigService;

    /**
     * 新增
     *
     * @param smsAccessConfig 实体
     * @return true/false
     */
    @PostMapping
    @ApiOperation("新增")
    public R save(@RequestBody SmsAccessConfig smsAccessConfig) {
        return R.ok(smsAccessConfigService.save(smsAccessConfig));
    }

    /**
     * 根据id查看
     *
     * @param id
     * @return SmsAccessConfig
     */
    @GetMapping("/{id}")
    @ApiOperation("根据id查看")
    public R<SmsAccessConfig> getById(@PathVariable String id) {
        return R.ok(smsAccessConfigService.getById(id));
    }

    /**
     * 分页查询
     *
     * @param params 分页对象
     * @return 分页对象
     */
    @PostMapping("/page")
    @ApiOperation("分页查询")
    public IPage<SmsAccessConfig> page(@RequestBody Map<String, Object> params) {
        return smsAccessConfigService.page(new Query<>(params));
    }

    /**
     * 根据id删除
     *
     * @param id
     * @return true/false
     */
    @DeleteMapping("/{id}")
    @ApiOperation("根据id删除")
    public R removeById(@PathVariable String id) {
        return R.ok(smsAccessConfigService.removeById(id));
    }

    /**
     * 根据id修改
     *
     * @param smsAccessConfig 实体
     * @return true/false
     */
    @PutMapping
    @ApiOperation("根据id修改")
    public R updateById(@RequestBody SmsAccessConfig smsAccessConfig) {
        return R.ok(smsAccessConfigService.updateById(smsAccessConfig));
    }

}

